package com.kotlin.goods.presenter

import com.kotlin.base.ext.excute
import com.kotlin.base.presenter.BasePresenter
import com.kotlin.base.rx.BaseSubscriber
import com.kotlin.goods.data.protocol.Category
import com.kotlin.goods.data.protocol.Goods
import com.kotlin.goods.presenter.view.CategoryView
import com.kotlin.goods.presenter.view.GoodsListView
import com.kotlin.goods.service.CategoryService
import com.kotlin.goods.service.GoodsService
import javax.inject.Inject


class GoodsListPresenter @Inject constructor() : BasePresenter<GoodsListView>() {
    @Inject
    lateinit var goodsService: GoodsService

    fun getGoodsList(categoryId: Int, pageNo: Int) {
        if (!checkNetWork()){
            return
        }
        mView.showLoading()
        goodsService.getGoodsList(categoryId,pageNo)
                .excute(object : BaseSubscriber<MutableList<Goods>?>(mView) {
                    override fun onNext(t: MutableList<Goods>?) {
                        super.onNext(t)
                        mView.onGetGoodsListResult(t)
                    }
                },lifecycleProvider)
    }

    fun getGoodsListByKeyword(keyword: String, pageNo: Int) {
        if (!checkNetWork()){
            return
        }
        mView.showLoading()
        goodsService.getGoodsListByKeyword(keyword,pageNo)
                .excute(object : BaseSubscriber<MutableList<Goods>?>(mView) {
                    override fun onNext(t: MutableList<Goods>?) {
                        super.onNext(t)
                        mView.onGetGoodsListResult(t)
                    }
                },lifecycleProvider)
    }
}